 <!-- Headers -->
<div class="container-fluid" style="padding:0;">
  <!-- Header -->
  <header class="header">
    <div class="page-header">
      <span class="logo glyphicon glyphicon-tasks"></span>
      <span class="title">项目详情</span>
    </div>
  </header>

  <!-- Sub Header -->
  <header class="header sub">
      <div class="row-fluid">
        <div class="toolbar" for="basic">
          <button type="button" class="btn btn-success" id="btn-basic-save" data-toggle="modal" data-target="#modal-project" data-backdrop="static" data-keyboard="false"><span class="glyphicon glyphicon-ok"></span> 保存</button>
          <button type="button" class="btn btn-default" for="btn-close"><span class="glyphicon glyphicon-remove danger"></span> 返回</button>
        </div>
        <div class="toolbar" for="users">
          <button type="button" class="btn btn-success" id="btn-user-new" data-toggle="modal" data-target="#modal-user" data-backdrop="static" data-keyboard="false"><span class="glyphicon glyphicon-plus"></span> 添加实施</button>
          <button type="button" class="btn btn-default" id="btn-user-active" disabled="disabled"><span class="glyphicon glyphicon-ok ok"></span> 激活</button>
          <button type="button" class="btn btn-default" id="btn-user-ban" disabled="disabled"><span class="glyphicon glyphicon-ban-circle danger"></span> 冻结</button>
          <button type="button" class="btn btn-default" for="btn-close"><span class="glyphicon glyphicon-remove danger"></span> 返回</button>
        </div>
        <div class="toolbar" for="modules">
          <button type="button" class="btn btn-success" id="btn-module-new" data-toggle="modal" data-target="#modal-module" data-backdrop="static" data-keyboard="false"><span class="glyphicon glyphicon-plus"></span> 添加模块</button>
          <button type="button" class="btn btn-default" id="btn-module-active" disabled="disabled"><span class="glyphicon glyphicon-ok ok"></span> 激活</button>
          <button type="button" class="btn btn-default" for="btn-close"><span class="glyphicon glyphicon-remove danger"></span> 返回</button>
        </div>
        <div class="toolbar" for="materials">
          <button type="button" class="btn btn-success" id="btn-material-new" data-toggle="modal" data-target="#modal-material" data-backdrop="static" data-keyboard="false"><span class="glyphicon glyphicon-plus"></span> 添加材料</button>
          <button type="button" class="btn btn-default" id="btn-material-active" disabled="disabled"><span class="glyphicon glyphicon-ok ok"></span> 激活</button>
          <button type="button" class="btn btn-default" id="btn-material-ban" disabled="disabled"><span class="glyphicon glyphicon-ban-circle danger"></span> 冻结</button>
          <button type="button" class="btn btn-default" for="btn-close"><span class="glyphicon glyphicon-remove danger"></span> 返回</button>
        </div>
        <div class="toolbar pull-right" for="shared">
          <button type="button" class="btn btn-default btn-xs" id="btn-refresh"><span class="glyphicon glyphicon-refresh"></span> 刷新</button>
          <button type="button" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span> 选项</button>
          <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#help"><span class="glyphicon glyphicon-question-sign"></span> 帮助</button>
        </div>
      </div>
  </header>
</div>
<!-- Main component for a primary marketing message or call to action -->
<div class="container-fluid body">
	<!-- Nav tabs -->
	<ul class="nav nav-tabs">
	  <li class="active"><a href="#basic" data-toggle="tab">基本信息</a></li>
	  <li><a href="#users" data-toggle="tab">项目实施</a></li>
 	  <li><a href="#modules" data-toggle="tab">施工模块</a></li>
	  <li><a href="#materials" data-toggle="tab">材料清单</a></li>
	  <li><a href="#acceptance" data-toggle="tab">材料验收</a></li>
	</ul>

	<!-- Tab panes -->
	<div class="tab-content">
	  <div class="tab-pane active" id="basic">
	  	<br>
	  	<div class="alert alert-success">项目基本信息。</div>
   		<form method='post' action='project/edit' class="form-horizontal" id="form-basic">
          <input type="hidden" name="id">
          <div class="form-group">
            <label class="col-sm-2 control-label">项目名称</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="name" placeholder="项目名称">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">项目描述</label>
            <div class="col-sm-10">
              <textarea class="form-control" rows="3" name="desc" placeholder="填写项目描述信息"></textarea>
            </div>
          </div>
        </form>
	  </div>
	  <div class="tab-pane" id="users">
	  	<br>
	  	<div class="alert alert-success">每个项目可以创建一个材料员和施工员。</div>
	  	<table class="table table-striped table-bordered" id="table-users">
	      <thead>
	        <tr>
	          <th width="1%" class="nowrap center"><input type="checkbox" role="check-all"/></th>
	          <th width="15%">账号</th>
	          <th width="5%">状态</th>
	          <th width="10%">角色</th>
	          <th width="20%">最近登录时间</th>
	          <th width="10%">最近登录IP</th>
	        </tr>
	      </thead>
	      <tbody>
	        <tr>
	          <td colspan="6" class="dataTables_empty">数据加载中...</td>
	        </tr>
	      </tbody>
	    </table>
	  </div>
	  <div class="tab-pane" id="modules">
	  	<br>
	  	<div class="alert alert-success">在这里划分项目施工模块。</div>
	  	<table class="table table-striped table-bordered" id="table-modules">
	      <thead>
	        <tr>
	          <th width="1%" class="nowrap center"><input type="checkbox" role="check-all"/></th>
	          <th width="10%">名称</th>
	          <th width="5%">状态</th>
	          <th width="30%">描述</th>
	          <th width="15%">备注</th>
	        </tr>
	      </thead>
	      <tbody>
	        <tr>
	          <td colspan="6" class="dataTables_empty">数据加载中...</td>
	        </tr>
	      </tbody>
	    </table>
	  </div>
	  <div class="tab-pane" id="materials">
	  	<br>
	  	<div class="alert alert-success">每个项目可以闯将一个材料员和施工员。</div>
	  	<table class="table table-striped table-bordered" id="table-materials">
	      <thead>
	        <tr>
	          <th width="1%" class="nowrap center"><input type="checkbox" role="check-all"/></th>
	          <th width="10%">名称</th>
	          <th width="2%">类别</th>
	          <th width="5%">类型</th>
	          <th width="5%">规格型号</th>
   	          <th width="5%">数量</th>
   	          <th width="5%">单位</th>
   	          <th width="5%">库存</th>
   	          <th width="5%">已使用</th>
   	          <th width="5%">运输中</th>
   	          <th width="5%">预算单价</th>
   	          <th width="5%">计划标志</th>
	        </tr>
	      </thead>
	      <tbody>
	        <tr>
	          <td colspan="12" class="dataTables_empty">数据加载中...</td>
	        </tr>
	      </tbody>
	    </table>
	  </div>
	</div>
</div>
<!-- Modals -->
<!--- User Add -->
<div class="modal fade" id="modal-user" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">新建实施</h4>
      </div>
      <div class="modal-body">
        <div class="alert alert-success hide" for="alert"></div>
        <form method='post' action='user/project/add' class="form-horizontal" id="form-user">
          <input type="hidden" name="project">
          <div class="form-group">
            <label class="col-sm-2 control-label">角色</label>
            <div class="col-sm-10">
              <select name="role" class="form-control">
                <option value="5">材料员</option>
                <option value="6">施工员</option>
              </select>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" role="submit">&nbsp;确&nbsp;&nbsp;定&nbsp;</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">&nbsp;取&nbsp;&nbsp;消&nbsp;</button>
      </div>
    </div>
  </div>
</div>
<!--- Module Add -->
<div class="modal fade" id="modal-module" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">新建施工模块</h4>
      </div>
      <div class="modal-body">
        <div class="alert alert-success hide" for="alert"></div>
        <form method='post' action='module/add' class="form-horizontal" id="form-module">
          <input type="hidden" name="project">
          <div class="form-group">
            <label class="col-sm-2 control-label">名称</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="name" placeholder="模块名称">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">描述</label>
            <div class="col-sm-10">
              <textarea class="form-control" rows="4" name="desc" placeholder="填写描述信息"></textarea>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">备注</label>
            <div class="col-sm-10">
              <textarea class="form-control" rows="2" name="desc" placeholder="填写备注说明"></textarea>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" role="submit">&nbsp;确&nbsp;&nbsp;定&nbsp;</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">&nbsp;取&nbsp;&nbsp;消&nbsp;</button>
      </div>
    </div>
  </div>
</div>
<!-- Material Add -->
<div class="modal fade" id="modal-material" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">添加材料</h4>
      </div>
      <div class="modal-body">
        <div class="alert alert-success hide" for="alert"></div>
        <form method='post' action='material/add' class="form-horizontal" id="form-material">
          <input type="hidden" name="project">
          <div class="form-group">
            <label class="col-sm-2 control-label">名称</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="name" placeholder="材料名称">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">物资类别</label>
            <div class="col-sm-10">
	            <div class="btn-group" data-toggle="buttons">
				  <label class="btn btn-default">
				    <input type="radio" name="class"> &nbsp;&nbsp;A&nbsp;&nbsp;
				  </label>
				  <label class="btn btn-default">
				    <input type="radio" name="class"> &nbsp;&nbsp;B&nbsp;&nbsp;
				  </label>
				  <label class="btn btn-default">
				    <input type="radio" name="class"> &nbsp;&nbsp;C&nbsp;&nbsp;
				  </label>
				</div>
			</div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">分类</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="model" placeholder="材料分类：钢材、电线等">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">规格型号</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="model" placeholder="材料规格型号">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">预算单价</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="unit" placeholder="材料预算单价">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">数量</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="unit" placeholder="材料数量">
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">单位</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="unit" placeholder="材料单位：m、个等">
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" role="submit">&nbsp;确&nbsp;&nbsp;定&nbsp;</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">&nbsp;取&nbsp;&nbsp;消&nbsp;</button>
      </div>
    </div>
  </div>
</div>

<link rel="stylesheet" type="text/css" href="css/jquery.table.min.css">
<script type="text/javascript" language="javascript" src="js/jquery.cookie.min.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.table.min.js"></script>
<script type="text/javascript" charset="utf-8">
	
	function change_selection() {
		var total = $($.project.current).find('td').find(':input[name=id]').length;
		var selected = $($.project.current).find('td').find(':checked').length;
		if (total > 0 && total == selected) $($.project.current).find('input[role="check-all"]').prop('checked', true);
	    else $($.project.current).find('input[role="check-all"]').prop('checked', false);
	    // fix buttons
	    if ($.project.current == '#users') {
	    	if (selected > 0) { 
	    		$("#btn-user-active").attr('disabled',false); 
	      		$("#btn-user-ban").attr('disabled',false); 
	    	} else {
	    		$("#btn-user-active").attr('disabled',true); 
	      		$("#btn-user-ban").attr('disabled',true); 
	    	}
	    }
	    return false;
	}

	function _table_selected() {
		var ids = [];
	    $($.project.current).find('td').find(':checked').each(function() {
	        ids.push($(this).attr('value'));
	    });
	    return ids;
	}

	$( document ).ready(function() {
		$.project = {
	        baisc: true,
	        users: true,
	        modules: true,
	        materials: true,
	        tables: {}
	    };

	    var _project_basic = function(project) {
	    	$.ajax({
		        url: "project/detail",
		        data: 'id=' + project,
		        success: function(data, status) {
		          if (data == undefined || data.project == undefined) {
		            $.global.error = true;
		            $("#basic").find(':input[name=id]').val('');
		            $("#basic").find(':input[name=name]').val('');
		            $("#basic").find(':input[name=desc]').val('');
		            $("#modal-load").find("img").attr('src', 'images/warn.png');
		            $("#modal-load").find("span").attr('class', 'label label-warning').html('项目详情加载失败，请稍后再试。');
		            $("#basic").find('.alert').html("项目详情加载失败，请稍后再试。").attr("class", "alert alert-danger");
		            $.project.basic = true;
		            setTimeout(function(){$('#modal-load').modal('hide')} , $.global.timeout);
		          } else {
		            $.global.error = false;
		            $("#basic").find(':input[name=id]').val(data.project.id);
		            $("#basic").find(':input[name=name]').val(data.project.name);
		            $("#basic").find(':input[name=desc]').val(data.project.desc);
		            $("#modal-project").find(".modal-title").html("修改项目信息");
		            $('#modal-project').modal({backdrop: 'static',show:true, keyboard: false});
		            $.project.basic = false;
		          }
		        },
		        error: function(hxr, status, error) {
		        	$("#basic").find(':input[name=id]').val('');
		            $("#basic").find(':input[name=name]').val('');
		            $("#basic").find(':input[name=desc]').val('');
		          	$("#modal-load").find("img").attr('src', 'images/warn.png');
		          	$("#modal-load").find("span").attr('class', 'label label-warning').html('项目详情加载失败，请稍后再试。');
		          	$("#basic").find('.alert').html("项目详情加载失败，请稍后再试。").attr("class", "alert alert-danger");
		          	$.project.basic = true;
		          	setTimeout(function(){$('#modal-load').modal('hide')} , $.global.timeout);
		        }
		    }); 
	    }

	    var _project_users = function(project) {
	    	$.project.tables.users.find('input[name="id"]').prop('checked', false);	 
	    	change_selection();   	
	    	$.project.tables.users.fnReloadAjax();
	    }

	    var _project_modules = function(project) {
	    	$.project.tables.users.find('input[name="id"]').prop('checked', false);	 
	    	change_selection();   	
	    	$.project.tables.modules.fnReloadAjax();
	    }

	    var _project_materials = function(project) {
	    	$.project.tables.materials.find('input[name="id"]').prop('checked', false);	 
	    	change_selection();   	
	    	$.project.tables.materials.fnReloadAjax();
	    }

	    var _refesh = function() {
	    	$.global.error = false;
	    	$("#modal-load").find("img").attr('src', 'images/loader.gif');
	        $("#modal-load").find("span").attr('class', 'label label-info').html('内容加载中，请稍后...');
			if ($.project.current == '#basic') {
				_project_basic(project);
			} else if ($.project.current == '#users') {
				_project_users(project);
			} else if ($.project.current == '#modules') {
				_project_modules(project);	
			} else if ($.project.current == '#materials') {
				_project_materials(project);
			}
		}

	    var project = $.cookie('project');

		$('button[for=btn-close]').click(function() {
			$.global.project = undefined;
		    load_content('project/projects.html');
		});

		// basic
		$("#btn-basic-save").click(function() {
			var form = $("#form-basic");
		    $.ajax({
		        type: form.attr('method'),
		        url: form.attr('action'),
		        data: form.serialize(),
		        success: function(data, status) {
		          if (data == undefined || data.status == undefined || data.status != 0) {
		            if (data == undefined || data.status == undefined) {
		            	$("#basic").find('.alert').html("服务端错误，请联系管理员！").attr("class", "alert alert-danger");
		            } else {
		              if (data.status == 1) {
		              	$("#basic").find('.alert').html("输入信息有误！").attr("class", "alert alert-warning");
		              } else {
		              	$("#basic").find('.alert').html("服务端异常，修改失败！").attr("class", "alert alert-danger");
		              }
		            }
		          } else {
		          	$("#basic").find('.alert').html("项目信息修改成功！").attr("class", "alert alert-success");
		          }
		        },
		        error: function(hxr, status, error) {
		        	$("#basic").find('.alert').html("服务端异常，修改失败！").attr("class", "alert alert-danger");
		        }
		    });
		});

		// users
		$("#btn-user-active").click(function() {
			$.ajax({
		        type: 'post',
		        url: 'user/active',
		        data: 'ids=' + _table_selected(),
		        success: function(data, status) {
		          if (data == undefined || data.status == undefined || data.status == 4) {
		            $.global.error = true;
		            $("#modal-load").find("img").attr('src', 'images/warn.png');
		            $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，请联系管理员！');
		            setTimeout(function(){_refesh()} , $.global.timeout);
		          } else {
		            if (data.status == -1) {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/cross.png');
		              $("#modal-load").find("span").attr('class', 'label label-danger').html('操作失败，非法操作！');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            } else if (data.status == 0) {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/accept.png');
		              $("#modal-load").find("span").attr('class', 'label label-success').html('操作成功，刷新数据。');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            } else {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/warn.png');
		              $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，操作失败！');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            }
		          }
		        },
		        error: function(hxr, status, error) {
		          $.global.error = true;
		          $("#modal-load").find("img").attr('src', 'images/warn.png');
		          $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，操作失败！');
		          setTimeout(function(){_refesh()} , $.global.timeout);
		        }
		    });
		});
		$("#btn-user-ban").click(function() {
			$.ajax({
		        type: 'post',
		        url: 'user/ban',
		        data: 'ids=' + _table_selected(),
		        success: function(data, status) {
		          if (data == undefined || data.status == undefined || data.status == 4) {
		            $.global.error = true;
		            $("#modal-load").find("img").attr('src', 'images/warn.png');
		            $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，请联系管理员！');
		            setTimeout(function(){_refesh()} , $.global.timeout);
		          } else {
		            if (data.status == -1) {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/cross.png');
		              $("#modal-load").find("span").attr('class', 'label label-danger').html('操作失败，非法操作！');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            } else if (data.status == 0) {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/accept.png');
		              $("#modal-load").find("span").attr('class', 'label label-success').html('操作成功，刷新数据。');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            } else {
		              $.global.error = true;
		              $("#modal-load").find("img").attr('src', 'images/warn.png');
		              $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，操作失败！');
		              setTimeout(function(){_refesh()} , $.global.timeout);
		            }
		          }
		        },
		        error: function(hxr, status, error) {
		          $.global.error = true;
		          $("#modal-load").find("img").attr('src', 'images/warn.png');
		          $("#modal-load").find("span").attr('class', 'label label-warning').html('服务端异常，操作失败！');
		          setTimeout(function(){_refesh()} , $.global.timeout);
		        }
		    });
		});

		$('#btn-refresh').click(_refesh);

		$("#form-user").submit(function() {return false;});
		$("#modal-user").find(':input[role=submit]').click(function() {
			var form = $("#form-user");
	        $.ajax({
		        type: form.attr('method'),
		        url: form.attr('action'),
		        data: form.serialize(),
		        success: function(data, status) {
		          if (data == undefined || data.status == undefined || data.status != 0) {
		            if (data == undefined || data.status == undefined) {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-danger').html('服务端错误，请联系管理员！').show();
		            } else {
		              if (data.status == 1) {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-warning').html('用户信息输入有误！').show();
		              } else if (data.status == 2) {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-warning').html('所选择项目不可用！').show();
	                  } else if (data.status == 5) {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-warning').html('角色存在不可添加！').show();
		              } else {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-danger').html(data.msg == undefined ? '服务端异常，用户添加失败！' : data.msg).show();
		              }
		            }
		          } else {
		            if (data.account == undefined) {
		                $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-danger').html('服务端错误，请联系管理员！').show();
	              	} else {
	                	$("#modal-user").find('div[for=alert]').attr('class', 'alert alert-success').html('用户添加成功，账号：<strong>' + data.account + '</strong>').show();
	                	$.project.tables.users.fnReloadAjax();
	              	}         
		          }
		        },
		        error: function(hxr, status, error) {
		          $("#modal-user").find('div[for=alert]').attr('class', 'alert alert-danger').html('服务端异常，用户添加失败！').show();
		        }
		    });
		    return false;
		});

		$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
		  	var target = $(e.target).attr("href");
		  	$.project.current = target;
		  	if (target == '#basic') {
		  		$.global.error = false;
	    		$("#modal-load").find("img").attr('src', 'images/loader.gif');
	        $("#modal-load").find("span").attr('class', 'label label-info').html('内容加载中，请稍后...');			
		  		$(".header.sub").find(".toolbar").hide();
		  		$(".header.sub").find("div[for=basic]").show();
		  		$(".header.sub").find("div[for=shared]").show();
		  		if ($.project.basic) _project_basic(project);
		  	} else if (target == '#users') {
		  		$.global.error = false;
	    		$("#modal-load").find("img").attr('src', 'images/loader.gif');
	        $("#modal-load").find("span").attr('class', 'label label-info').html('内容加载中，请稍后...');
		  		$(".header.sub").find(".toolbar").hide();
		  		$(".header.sub").find("div[for=users]").show();
		  		$(".header.sub").find("div[for=shared]").show();
		  		if ($.project.users) {
		  			var table = $('#table-users').dataTable( {
				      "bProcessing": false,
				      "bServerSide": true,
				      "bFilter": false,
				      "nPaging": true,
				      "bSort": false,
				      "bLengthChange": false,
				      "fnFailed": function (error, thrown) {
				        $.global.error = true;
				        $("#modal-load").find("img").attr('src', 'images/warn.png');
				        $("#modal-load").find("span").attr('class', 'label label-warning').html('内容加载失败，请稍后再试。');
				        setTimeout(function(){$('#modal-load').modal('hide')} , $.global.timeout);
				      },
				      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
				        $('td:eq(0)', nRow).html( '<input type="checkbox" name="id" value="' + aData[0] + '" onclick="change_selection();">' );
				        $('td:eq(2)', nRow).html( aData[2] == '0' ? '<span class="label label-warning">已禁用</span>' : '<span class="label label-success">使用中</span>' );
				        if (aData[3] == 5) {
				          $('td:eq(3)', nRow).html( '<span class="label label-warning">材料员</span>' );
				        } else if (aData[3] == 6) {
				          $('td:eq(3)', nRow).html( '<span class="label label-default">施工员</span>' );
				        } else {
				          $('td:eq(3)', nRow).html( '<span class="label label-danger">角色错误</span>' );
				        }
				        // Fix Login Info
				        if (aData[4] == '1000-01-01 00:00:00') $('td:eq(4)', nRow).html( '<span class="label label-default">从未登录</span>' );
				        if (aData[5] == '') $('td:eq(5)', nRow).html( '<span class="label label-default">未知</span>' );
				      },
				      "oLanguage": {
				        "sProcessing":   "处理中...",
				        "sLengthMenu":   "显示 _MENU_ 项结果",
				        "sZeroRecords":  "没有匹配结果",
				        "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
				        "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
				        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
				        "sInfoPostFix":  "",
				        "sSearch":       "搜索:",
				        "sUrl":          "",
				        "oPaginate": {
				          "sFirst":    "<span class='glyphicon glyphicon-backward'></span>",
				          "sPrevious": "<span class='glyphicon glyphicon-chevron-left'></span>",
				          "sNext":     "<span class='glyphicon glyphicon-chevron-right'></span>",
				          "sLast":     "<span class='glyphicon glyphicon-forward'></span>"
				        }
				      },
				      "sAjaxSource": "user/find?project=" + project
				    } );
 					$.project.users = false;
 					$.project.tables.users = table;
 				}
 			} else if (target == '#modules') {
 				  $.global.error = false;
	    	  $("#modal-load").find("img").attr('src', 'images/loader.gif');
	        $("#modal-load").find("span").attr('class', 'label label-info').html('内容加载中，请稍后...');
 				  $(".header.sub").find(".toolbar").hide();
		  		$(".header.sub").find("div[for=modules]").show();
		  		$(".header.sub").find("div[for=shared]").show();
		  		if ($.project.modules) {
		  			var table = $('#table-modules').dataTable( {
				      "bProcessing": false,
				      "bServerSide": true,
				      "bFilter": false,
				      "nPaging": true,
				      "bSort": false,
				      "bLengthChange": false,
				      "fnFailed": function (error, thrown) {
				        $.global.error = true;
				        $("#modal-load").find("img").attr('src', 'images/warn.png');
				        $("#modal-load").find("span").attr('class', 'label label-warning').html('内容加载失败，请稍后再试。');
				        setTimeout(function(){$('#modal-load').modal('hide')} , $.global.timeout);
				      },
				      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
				        $('td:eq(0)', nRow).html( '<input type="checkbox" name="id" value="' + aData[0] + '" onclick="change_selection();">' );
				        $('td:eq(2)', nRow).html( aData[2] == '0' ? '<span class="label label-warning">已禁用</span>' : '<span class="label label-success">使用中</span>' );
				        if (aData[3] == 5) {
				          $('td:eq(3)', nRow).html( '<span class="label label-warning">材料员</span>' );
				        } else if (aData[3] == 6) {
				          $('td:eq(3)', nRow).html( '<span class="label label-default">施工员</span>' );
				        } else {
				          $('td:eq(3)', nRow).html( '<span class="label label-danger">角色错误</span>' );
				        }
				        // Fix Login Info
				        if (aData[4] == '1000-01-01 00:00:00') $('td:eq(4)', nRow).html( '<span class="label label-default">从未登录</span>' );
				        if (aData[5] == '') $('td:eq(5)', nRow).html( '<span class="label label-default">未知</span>' );
				      },
				      "oLanguage": {
				        "sProcessing":   "处理中...",
				        "sLengthMenu":   "显示 _MENU_ 项结果",
				        "sZeroRecords":  "没有匹配结果",
				        "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
				        "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
				        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
				        "sInfoPostFix":  "",
				        "sSearch":       "搜索:",
				        "sUrl":          "",
				        "oPaginate": {
				          "sFirst":    "<span class='glyphicon glyphicon-backward'></span>",
				          "sPrevious": "<span class='glyphicon glyphicon-chevron-left'></span>",
				          "sNext":     "<span class='glyphicon glyphicon-chevron-right'></span>",
				          "sLast":     "<span class='glyphicon glyphicon-forward'></span>"
				        }
				      },
				      "sAjaxSource": "module/find?project=" + project
				    } );
 					$.project.modules = false;
 					$.project.tables.modules = table;
 				}
 			} else if (target == '#materials') {
 				  $.global.error = false;
	    		$("#modal-load").find("img").attr('src', 'images/loader.gif');
	        $("#modal-load").find("span").attr('class', 'label label-info').html('内容加载中，请稍后...');
 				  $(".header.sub").find(".toolbar").hide();
		  		$(".header.sub").find("div[for=materials]").show();
		  		$(".header.sub").find("div[for=shared]").show();
		  		if ($.project.materials) {
		  			var table = $('#table-materials').dataTable( {
				      "bProcessing": false,
				      "bServerSide": true,
				      "bFilter": false,
				      "nPaging": true,
				      "bSort": false,
				      "bLengthChange": false,
				      "fnFailed": function (error, thrown) {
				        $.global.error = true;
				        $("#modal-load").find("img").attr('src', 'images/warn.png');
				        $("#modal-load").find("span").attr('class', 'label label-warning').html('内容加载失败，请稍后再试。');
				        setTimeout(function(){$('#modal-load').modal('hide')} , $.global.timeout);
				      },
				      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
				        $('td:eq(0)', nRow).html( '<input type="checkbox" name="id" value="' + aData[0] + '" onclick="change_selection();">' );
				        $('td:eq(2)', nRow).html( aData[2] == '0' ? '<span class="label label-warning">已禁用</span>' : '<span class="label label-success">使用中</span>' );
				        if (aData[3] == 5) {
				          $('td:eq(3)', nRow).html( '<span class="label label-warning">材料员</span>' );
				        } else if (aData[3] == 6) {
				          $('td:eq(3)', nRow).html( '<span class="label label-default">施工员</span>' );
				        } else {
				          $('td:eq(3)', nRow).html( '<span class="label label-danger">角色错误</span>' );
				        }
				        // Fix Login Info
				        if (aData[4] == '1000-01-01 00:00:00') $('td:eq(4)', nRow).html( '<span class="label label-default">从未登录</span>' );
				        if (aData[5] == '') $('td:eq(5)', nRow).html( '<span class="label label-default">未知</span>' );
				      },
				      "oLanguage": {
				        "sProcessing":   "处理中...",
				        "sLengthMenu":   "显示 _MENU_ 项结果",
				        "sZeroRecords":  "没有匹配结果",
				        "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
				        "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
				        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
				        "sInfoPostFix":  "",
				        "sSearch":       "搜索:",
				        "sUrl":          "",
				        "oPaginate": {
				          "sFirst":    "<span class='glyphicon glyphicon-backward'></span>",
				          "sPrevious": "<span class='glyphicon glyphicon-chevron-left'></span>",
				          "sNext":     "<span class='glyphicon glyphicon-chevron-right'></span>",
				          "sLast":     "<span class='glyphicon glyphicon-forward'></span>"
				        }
				      },
				      "sAjaxSource": "material/find?project=" + project
				    } );
 					$.project.materials = false;
 					$.project.tables.materials = table;
 				}
		  	} else {
		  		console.log($(e.target).attr("href"));
		  	}
		})

 		// register all table's check-all
 		$("table").find('input[role="check-all"]').change(function() {
 			if ($(this).prop('checked')) {
		        $(this).parent().parent().parent().parent().find('tbody').find('input[name="id"]').prop('checked', true);
		    } else {
		        $(this).parent().parent().parent().parent().find('tbody').find('input[name="id"]').prop('checked', false);
		    }
		    change_selection();
	    });

 		$("#form-user").find("input[name=project]").val(project);
		$(".header.sub").find(".toolbar").hide();
		$(".header.sub").find("div[for=basic]").show();
		$(".header.sub").find("div[for=shared]").show();
		$.project.current = '#basic';
		_project_basic(project);
	})
</script>